package czh.cocoa.ui;

import java.util.Stack;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.webkit.MimeTypeMap;

import czh.cocoa.graphics.CGContext;
import czh.cocoa.graphics.CGImage;
import czh.cocoa.graphics.CGSize;

public class UIKit {
	
	private static Stack<CGContext> sContextStack;
	
	private static Stack<Bitmap> sImageStack;
	
	static {
		sContextStack = new Stack<CGContext>();
		sImageStack = new Stack<Bitmap>();
	}
	
	public static CGContext UIGraphicsGetCurrentContext() {
		return sContextStack.peek();
	}
	
	public static void UIGraphicsPushContext(CGContext ctx) {
		sContextStack.push(ctx);
	}
	
	public static void UIGraphicsPopContext() {
		sContextStack.pop();
	}
	
	public static void UIGraphicsBeginImageContext(CGSize size) {
		Bitmap bitmap = Bitmap.createBitmap((int)size.width, (int)size.height, Bitmap.Config.ARGB_8888);
		Canvas canvas = new Canvas(bitmap);
		CGContext ctx = new CGContext(canvas);
		sContextStack.push(ctx);
		sImageStack.push(bitmap);
	}
	
	public static UIImage UIGraphicsGetImageFromCurrentImageContext() {
		Bitmap bitmap = sImageStack.peek();
		return new UIImage(new CGImage(bitmap)); 
	}
	
	public static void UIGraphicsEndImageContext() {
		sContextStack.pop();
		sImageStack.pop();
	}

}
